package cn.wolfcode.web.controller;
import cn.wolfcode.domain.Employee;
import cn.wolfcode.qo.JsonResult;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {

    @RequestMapping("/login")
    @ResponseBody
    public JsonResult login(String username, String password){
        /*//获取主体对象
        Subject subject = SecurityUtils.getSubject();
        Employee employees = (Employee) subject.getPrincipal();

        //使用主体对象进行登录
        Md5Hash hash = new Md5Hash(password,employees.getName());
        UsernamePasswordToken token = new UsernamePasswordToken(username, hash.toString());
        subject.login(token);
        return new JsonResult();
*/
       /* Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        subject.login(token);
        return new JsonResult();*/

        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);

        subject.login(token);
        return new JsonResult();

    }
}
